
from xml.dom.minidom import parse
import xml.dom.minidom

import riftsClass
import riftsOptions
from rollDice import diceRoller

global options
RACETree = xml.dom.minidom.parse("raceList.xml")
collection = RACETree.documentElement

races = collection.getElementsByTagName("race")

class Race:
    def __init__(self, tree):
        self.Name = tree.getAttribute("name")
        self.Psionics = tree.getAttribute("psionics")
        self.Magic = tree.getAttribute("magic")
        self.Cybernetics = tree.getAttribute("cybernetics")
        self.Bonus = tree.getAttribute("bonus")
        self.AlignmentLimit = tree.getElementsByTagName("alignment")[0].childNodes[0].data
        self.IQ = tree.getElementsByTagName("IQ")[0].childNodes[0].data
        self.ME = tree.getElementsByTagName("ME")[0].childNodes[0].data
        self.MA = tree.getElementsByTagName("MA")[0].childNodes[0].data
        self.PS = tree.getElementsByTagName("PS")[0].childNodes[0].data
        self.PP = tree.getElementsByTagName("PP")[0].childNodes[0].data
        self.PE = tree.getElementsByTagName("PE")[0].childNodes[0].data
        self.PB = tree.getElementsByTagName("PB")[0].childNodes[0].data
        self.SPD = tree.getElementsByTagName("SPD")[0].childNodes[0].data
        self.Health = tree.getElementsByTagName("Health")[0]
        self.Classes = tree.getElementsByTagName("classRestriction")[0]
        self.Description = tree.getElementsByTagName("description")[0].childNodes[0].data

       
    def raceClassList(self,Classes):
        classes = Classes.copy()
        restrictList = self.Classes.childNodes[0].data.split(",")
        if self.Classes.getAttribute("type") == "NA" and self.Classes.childNodes[0].data == "ANY":
            print "ANY CLASS ALLOWED BY RACE LIMITS"
            pass
        elif self.Classes.getAttribute("type") == "ONLY":
            for i in classes.keys():
                if i not in restrictList:
                    print "DELETING " + i + " NOT IN ONLY LIST"
                    del classes[i]
        elif self.Classes.getAttribute("type") == "NOT":
            for i in classes.keys():
                if i in restrictList:
                    print "DELETING " + i + " IN NOT LIST"
                    del classes[i]
        elif self.Classes.getAttribute("type") == "ONLYtype":
            for i in classes.keys():
                compare = list(set(restrictList).intersection(set(Classes[i].Type)))
                if not compare:
                    print "DELETING " + i + " NOT ON TYPE WHITELIST"
                    del classes[i]
        elif self.Classes.getAttribute("type") == "NOTtype":
            for i in classes.keys():
                compare = list(set(restrictList).intersection(set(Classes[i].Type)))
                if compare:
                    print "DELETING " + i + " ON TYPE BLACKLIST"
                    del classes[i]
        else:
            print "FAILED THE CLASS SORTING"
            pass
        return classes

def getRaceList():
    dictOfRaces = {"":""}
    for item in races:
        race = Race(item)
        dictOfRaces.update({race.Name:race})
    return dictOfRaces

if __name__ == "__main__":
    dictOfRaces = {"":""}
    for item in races:
        race = Race(item)
        dictOfRaces.update({race.Name:race})
